﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HWBrainFxxxckEasy
{
    class Program
    {
        static string ConvertBackToBrain(string str)
        {
            StringBuilder buldString = new StringBuilder();
            char[] charVar = str.ToCharArray();
            int tempInt = 32;
            int flag=0;

            for (int i = 0; i <= charVar.Length - 1; i++)
            {
                int currentCharIntValue = Convert.ToInt32(charVar[i]);

                if (tempInt < currentCharIntValue)
                {
                    for (int j = tempInt; j < currentCharIntValue; j++)
                    {
                        if ((i < (charVar.Length - 1)) && (j == Convert.ToInt32(charVar[i + 1])))
                        {
                            buldString.Append("%+");
                            charVar[i + 1] = Convert.ToChar(j);
                            flag = 1;
                        }
                        else
                        {
                            buldString.Append("+");
                        }
                    }
                }
                else if (tempInt > currentCharIntValue)
                {
                    for (int k = tempInt; k > currentCharIntValue; k--)
                    {
                        if ((i < (charVar.Length - 1)) && (k == Convert.ToInt32(charVar[i + 1])))
                        {
                            buldString.Append("%-");
                            charVar[i + 1] = Convert.ToChar(k);
                            flag = 1;
                        }
                        else
                        {
                            buldString.Append("-");
                        }
                    }
                }

                if ((i < (charVar.Length - 1)) && (currentCharIntValue < Convert.ToInt32(charVar[i + 1])))
                {
                    if (flag != 1)
                    {
                        buldString.Append("%");
                        tempInt = currentCharIntValue;
                        
                    }
                    else
                    {
                        tempInt = Convert.ToInt32(charVar[i + 1]);
                        flag = 0;
                    }
                }
                else if ((i < (charVar.Length - 1)) && (currentCharIntValue > Convert.ToInt32(charVar[i + 1])))
                {
                    if (flag != 1)
                    {
                        buldString.Append("%");
                        tempInt = currentCharIntValue;
                        
                    }
                    else
                    {
                        tempInt = Convert.ToInt32(charVar[i + 1]);
                        flag = 0;
                    }
                }
                else
                {
                    tempInt = currentCharIntValue;
                }

                if (i == (charVar.Length-1))
                {
                    buldString.Append("@");
                }
                else
                {
                    buldString.Append(">");
                }
            }
            return buldString.ToString();
        }

        static void ConverFromBrain(string str)
        {
            char[] array = new char[] { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };
            int memoryCounter = 0;
            foreach (char letter in str)
            {
                switch (letter)
                {
                    case '+':
                        array[memoryCounter]++;
                        break;
                    case '-':
                        array[memoryCounter]--;
                        break;
                    case '>':
                        while (memoryCounter <= array.Length)
                        {
                            memoryCounter++;
                            break;
                        }
                        break;
                    case '<':
                        while (memoryCounter >= array.Length)
                        {
                            memoryCounter--;
                            break;
                        }
                        break;
                    case '@':
                        Console.WriteLine(array);
                        break;
                    case '%':
                        array[memoryCounter + 1] = array[memoryCounter];
                        break;
                    case '!':
                        array[memoryCounter] = Convert.ToChar(32);
                        break;
                }
            }
        }

        static void Main(string[] args)
        {

            Console.WriteLine(ConvertBackToBrain("Language"));
            ConverFromBrain(ConvertBackToBrain("Language"));
            Console.WriteLine(ConvertBackToBrain("Timur"));
            ConverFromBrain(ConvertBackToBrain("Timur"));
            Console.WriteLine(ConvertBackToBrain("Andrey"));
            ConverFromBrain(ConvertBackToBrain("Andrey"));
            Console.ReadLine();
        }

    }
}
 